<?php
    defined('M2_MICRO') or die('Direct Access to this location is not allowed.');

    /**
      * Form Controller class
      * @name $formController
      * @package M2 Micro Framework
      * @subpackage Modules
      * @author Alexander Chaika
      */
    class FormController extends Controller {

        /**
          * Dispatch action which call action method
          * and setup default module options
          * @return mixed $result
          */
        public function dispatch() {
            // route task
            $task = System::getInstance()->getCmd('task', 'mailer');

            $options = array();
            $method = $task.'Action';
            if (is_callable(array($this, $method))) {
                return $this->$method($options);
            } else {
                return $this->indexAction($options);
            }
        }

        /**
          * Default module action
          * @return mixed $result
          */
        private function indexAction($options) {
            // route default action
            return $this->mailerAction($options);
        }

        /**
          * Return mailer form
          * @param array $options
          * @return mixed $result
          */
        private function mailerAction($options) {
            // set output format for this action
            $options['format'] = 'page';
            
            // get form contents
            $options['name'] = 'mailer';
            $options['type'] = 'form';
            $options['data'] = $this->view->getContents($options);
            
            return $options;
        }
    }
?>